package com.util;


import java.io.Serializable;
import java.util.AbstractSet;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ConcurrentHashSet<E> extends AbstractSet<E> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	protected Map<E, Boolean> map = null;
	
	public ConcurrentHashSet(){
		this.map = new ConcurrentHashMap<E,Boolean>();
	}

	@Override
	public boolean contains(Object o) {
		return map.containsKey(o);
	}
	
	@Override
	public boolean add(E e) {
		return map.putIfAbsent(e, Boolean.TRUE) == null;
	}
	
	@Override
	public boolean remove(Object o) {
		return map.remove(o) != null;
	}
	
	@Override
	public Iterator<E> iterator() {
		return map.keySet().iterator();
	}

	@Override
	public int size() {
		return map.size();
	}
	
	@Override
	public void clear() {
		map.clear();
	}

}
